package ThreadDemo.src;

/*
 * Author: JacksonCoder
 * FileName: NewThread
 * Version: 1.0.0
 */
public class NewThread {
    public static void main(String[] args) throws InterruptedException {
//        Thread t = new Thread();
//        t.start();
        // 方法1
        Thread oneThread = new OneThread();
        oneThread.start();
        // 方法2
        Thread oneRunnable = new Thread(new OneRunnable());
        oneRunnable.start();

        Thread lambdaThread = new Thread(()->{
            System.out.println("this is lambda thread: " + Thread.currentThread().getName());
        });
        lambdaThread.start();

        Thread t2 = new Thread(()->{
            System.out.println("hello");
        });
        System.out.println("start");
        t2.start(); // start thread t
        t2.join(); // wait for thread t2 to finish
        System.out.println("end");
    }
}



class OneRunnable implements Runnable{
    @Override
    public void run(){
        System.out.println("start new thread: " + Thread.currentThread().getName());
    }
}

class OneThread extends Thread{
    @Override
    public void run(){
        System.out.println("这是一个线程 " + Thread.currentThread().getName());
    }
}